/*
 * cpu.h
 *
 *  Created on: Feb 18, 2013
 *      Author: ismith
 */

#ifndef CPU_H_
#define CPU_H_

#define IP0_REG_INDEX 12
#define IP1_REG_INDEX 13
#define BP_REG_INDEX 14
#define SP_REG_INDEX 15

#define IVT_START 0x2100

#include <stdlib.h>
#include "alu.h"
#include "ioctl.h"
#include "memory.h"
#include "register.h"
#include "registerFile.h"
#include "global.h"

#define N_BIT_POS 15
#define Z_BIT_POS 14
#define C_BIT_POS 13
#define O_BIT_POS 12

typedef struct {
	AluPtr alu;
	IoctlPtr ioctl;
	MemoryPtr memory;
	RegisterFilePtr reg_file;

	RegisterPtr pc;
	RegisterPtr ir;
	RegisterPtr sw;
	RegisterPtr osb;
	RegisterPtr txb;

	Bit stop;
} CpuStr;

typedef CpuStr * CpuPtr;

CpuPtr cpu_new_cpu(MemoryPtr memory);
void cpu_free(CpuPtr cpu);
void cpu_initialize(CpuPtr cpu);

void cpu_set_pc(CpuPtr cpu, RegisterStr new_pc);
void cpu_step(CpuPtr cpu);

RegisterStr cpu_get_pc(CpuPtr cpu);
RegisterStr cpu_get_ir(CpuPtr cpu);
RegisterStr cpu_get_sw(CpuPtr cpu);

Bit cpu_get_stop_bit(CpuPtr cpu);
void cpu_reset_stop_Bit(CpuPtr cpu);

#endif /* CPU_H_ */
